using log4net;
using System;
using System.Web;
using PicStore.Common.Exceptions;
using Elmah;

namespace PicStore.Common.Log
{
    public class Log4Net:ILog
    {

        static log4net.ILog log = (log4net.ILog)LogManager.GetLogger("APPLogger");

        public void Info(string message)
        {
            log.Info(message);
        }

        public void Warning(string message)
        {
            log.Warn(message);
        }

        public void Debug(string message)
        {
            log.Debug(message);
        }

        public void Debug(string message, Exception ex)
        {
            ExceptionWrapper.WrapMessage(ref message, ex);
            log.Debug(message);
        }

        public void Severe(string message)
        {
            log.Fatal(message);
            var context = HttpContext.Current;
            if(context != null)
            {
                ErrorLog.GetDefault(context).Log(new Error(new Exception(message), context));
            }
        }

        public void Severe(string message, Exception ex)
        {
            ExceptionWrapper.WrapMessage(ref message, ex);
            log.Fatal(message);
        }
    }
}